'''
Created on 2020年1月30日
获取所有股票数据
@author: JM
'''
import pandas as pd

from app_config import get_engine_ts, get_pro, get_engine
from sqlalchemy import text
engine = get_engine()


def read_data():
    sql = """SELECT * FROM index_basic"""
    df = pd.read_sql_query(sql, engine)
    return df


def write_data(data_frame):
    res = data_frame.to_sql('index_basic', engine, index=False, if_exists='append', chunksize=5000)
    print(res)

def rewrite_data(data_frame):
    sql = """TRUNCATE TABLE index_basic"""
    with engine.connect() as conn:
        conn.execute(text(sql))
    res = data_frame.to_sql('index_basic', engine, index=False, if_exists='append', chunksize=5000)
    print(res)

def get_data():
    data = get_pro().index_basic()
    return data

if __name__ == '__main__':
    #     df = read_data()
    df = get_data()
    write_data(df)
    print(df)
